import api from '@/api'

export default {
  data() {
    return {
      props: {
        multiple: true,
        checkStrictly: true,
        lazy: true,
        lazyLoad(node, resolve) {
          setTimeout(() => {
            if (node.level === 0) {
              const arr = []
              api.getGoodsCategoryList({ parentId: 0, page: 1, pageSize: 999 }).then(response => {
                response.list.forEach((item, index) => {
                  arr.push(
                    {
                      value: item.goodsCategoryId,
                      label: item.categoryName,
                      leaf: false
                    }
                  )
                })
                resolve(arr)
              })
            }
            if (node.level === 1) {
              // eslint-disable-next-line no-redeclare
              const arr = []
              api.getGoodsCategoryList({ parentId: node.value, page: 1, pageSize: 999 }).then(response => {
                response.list.forEach((item, index) => {
                  arr.push(
                    {
                      value: item.goodsCategoryId,
                      label: item.categoryName,
                      leaf: false
                    }
                  )
                })
                resolve(arr)
              })
            } else if (node.level === 2) {
              // eslint-disable-next-line no-redeclare
              const arr = []
              api.getGoodsCategoryList({ parentId: node.value, page: 1, pageSize: 999 }).then(response => {
                response.list.forEach((item, index) => {
                  arr.push(
                    {
                      value: item.goodsCategoryId,
                      label: item.categoryName,
                      leaf: true
                    }
                  )
                })
                resolve(arr)
              })
            } else {
              resolve([])
            }
          }, 100)
        }
      }
    }
  }
}
